//
//  CreateUserTask.m
//  ZooNgonDoiOS
//
//  Created by Anh Jun Linh Tinh on 6/26/12.
//  Copyright (c) 2012 Personal. All rights reserved.
//

#import "CreateUserTask.h"
#import "ZooSignupNetwork.h"
#import <RestKit/JSONKit.h>

@implementation CreateUserTask
-(id)initWithParams:(NSString *)user pass:(NSString *)pass email:(NSString *)email phone:(NSString *)phone{
    self = [super init];
    if(self){
        _user = user;
        _pass = pass;
        _email = email;
        _phone = phone;
        _zooSignupResponse = [[ZooSignupResponse alloc]init];
    }
    return self;
}

-(void)doExecute:(NSObject<RKRequestDelegate> *)pDelegate {
    NSDictionary *params = [NSDictionary dictionaryWithKeysAndObjects:@"username",_user,@"password",_pass,@"email",_email, @"phone", _phone,nil];
//    ZooSignupNetwork *zooSignupNetwork = [[ZooSignupNetwork alloc]initWithTarget:self selector:@selector(onSignupOK)];

    [[RKObjectManager sharedManager].client put:@"/create_user" params:params delegate:pDelegate];
}

-(void)request:(RKRequest *)request didFailLoadWithError:(NSError *)error{
    NSLog(@"cde %@",[request.response bodyAsString]);
    NSLog(@"%@",error);
}

//-(void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response{
//    NSLog(@"xxxxxxxxxxx %d",[response statusCode]);
//
//    NSNumber *aStatus;
//    NSString *aError;
//    if ([request isPUT]) {
//        
//        NSString *myJson = [response bodyAsString];
//        NSDictionary *parseJSON = [myJson objectFromJSONString];
//        aStatus = [parseJSON objectForKey:STATUS]; 
//        aError = [parseJSON objectForKey:ERROR_RESPONSE];
//        NSLog(@"%@",aStatus);
//        
//        if ([aStatus isEqualToNumber:[NSNumber numberWithInt:0]]) {
//            _zooSignupResponse.status = false;
//            _zooSignupResponse.error = [parseJSON objectForKey:ERROR_RESPONSE];
//            _zooSignupResponse.errorCode = [parseJSON objectForKey:ERROR_CODE_RESPONSE];
//        } else {
//            _zooSignupResponse.status = true;
//        }
//        
////        if ([response isOK]) {
////            NSString *myJson = [response bodyAsString];
////            NSDictionary *parseJSON = [myJson objectFromJSONString];
////            aStatus = [parseJSON objectForKey:STATUS];  
////            _zooSignupResponse.status = aStatus;
////            
////        } else if ([response isClientError]) {
////            NSString *myJson = [response bodyAsString];
////            NSDictionary *parseJSON = [myJson objectFromJSONString];
////            aStatus = [parseJSON objectForKey:STATUS];
////            
////            NSString *error = [parseJSON objectForKey:ERROR_RESPONSE];
////            NSString *error_code = [parseJSON objectForKey:ERROR_CODE_RESPONSE];
////            NSLog(@"error: %@, error_code: %@", error, error_code);
////        }
//
//    }
//}

@end
